home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 675 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.8 KB

  1. From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
  2. Message-ID: <4hr3tl$b53@mulga.cs.mu.OZ.AU>
  3. X-Original-Date: 9 Mar 1996 05:11:17 GMT
  4. Path: in2.uu.net!bounce-back
  5. Date: 09 Mar 96 05:55:44 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: delete or delete[] ???
  9. Organization: Comp Sci, University of Melbourne
  10. References: <4hnqvf$mgr@fsgi01.fnal.gov>
  11. Keywords: delete
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBFAgUBMUEdd+EDnX0m9pzZAQEWSAGAnx5lH44n7vkk1u+sF62/TECUZ0lnP7v+
  14.     qymn/TUbeazppk+5LnIcvUmZpuoH+C5m
  15.     =xrIY
  16.  
  17. b91926@fsgi01.fnal.gov (David Sachs) writes:
  18.  
  19. >Should delete or delete[] be used for a pointer to an array type?
  20.  
  21. `delete[]' should be used.
  22.  
  23. See 5.3.5[expr.delete]/2, which says (amoung other things)
  24. that the syntax of the delete expression must match the *type* of
  25. the corresponding new expression, not its *syntax*.
  26.  
  27. >// It is assumed that some_type is an existing type
  28. >typedef some_type array_type[10];
  29. >
  30. >array_type* a1 = new array_type[5];
  31. >array_type* b1 = new some_type[5][10];
  32. >array_type* a2 = new array_type;
  33. >array_type* b2 = new some_type[10];
  34. >...
  35. >delete[] a1;
  36. >delete[] b1;
  37. >delete   a2; // or should it be delete[] a2;
  38.  
  39. Yes, it should be `delete[] a2;'.
  40.  
  41. >delete[] b2; // or should it be delete   b2;
  42.  
  43. Nope, that one is correct.
  44.  
  45. --
  46. Fergus Henderson                 WWW: http://www.cs.mu.oz.au/~fjh
  47. fjh@cs.mu.oz.au                  PGP: finger fjh@128.250.37.3
  48. ---
  49. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  50. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  51. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  52. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  53. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  54.